home *** CD-ROM | disk | FTP | other *** search
Wrap
Public Class CallerForm Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Friend WithEvents lblMessage As System.Windows.Forms.Label Friend WithEvents btnShowModeless As System.Windows.Forms.Button Friend WithEvents btnShowModal As System.Windows.Forms.Button Friend WithEvents btnMessageBox As System.Windows.Forms.Button Friend WithEvents Button1btnShowOwned As System.Windows.Forms.Button 'Required by the Windows Form Designer Private components As System.ComponentModel.Container 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.btnMessageBox = New System.Windows.Forms.Button() Me.btnShowModal = New System.Windows.Forms.Button() Me.lblMessage = New System.Windows.Forms.Label() Me.Button1btnShowOwned = New System.Windows.Forms.Button() Me.btnShowModeless = New System.Windows.Forms.Button() Me.SuspendLayout() ' 'btnMessageBox ' Me.btnMessageBox.Location = New System.Drawing.Point(32, 120) Me.btnMessageBox.Name = "btnMessageBox" Me.btnMessageBox.Size = New System.Drawing.Size(280, 40) Me.btnMessageBox.TabIndex = 0 Me.btnMessageBox.Text = "Show Message Box" ' 'btnShowModal ' Me.btnShowModal.Location = New System.Drawing.Point(32, 168) Me.btnShowModal.Name = "btnShowModal" Me.btnShowModal.Size = New System.Drawing.Size(280, 40) Me.btnShowModal.TabIndex = 0 Me.btnShowModal.Text = "Show Modal Form" ' 'lblMessage ' Me.lblMessage.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.lblMessage.Location = New System.Drawing.Point(32, 232) Me.lblMessage.Name = "lblMessage" Me.lblMessage.Size = New System.Drawing.Size(280, 56) Me.lblMessage.TabIndex = 1 ' 'Button1btnShowOwned ' Me.Button1btnShowOwned.Location = New System.Drawing.Point(32, 72) Me.Button1btnShowOwned.Name = "Button1btnShowOwned" Me.Button1btnShowOwned.Size = New System.Drawing.Size(280, 40) Me.Button1btnShowOwned.TabIndex = 0 Me.Button1btnShowOwned.Text = "Show Modeless Owned Form" ' 'btnShowModeless ' Me.btnShowModeless.Location = New System.Drawing.Point(32, 24) Me.btnShowModeless.Name = "btnShowModeless" Me.btnShowModeless.Size = New System.Drawing.Size(280, 40) Me.btnShowModeless.TabIndex = 0 Me.btnShowModeless.Text = "Show Modeless Form" ' 'CallerForm ' Me.AutoScaleBaseSize = New System.Drawing.Size(7, 17) Me.ClientSize = New System.Drawing.Size(344, 309) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1btnShowOwned, Me.btnMessageBox, Me.btnShowModal, Me.lblMessage, Me.btnShowModeless}) Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Name = "CallerForm" Me.Text = "CallerForm" Me.ResumeLayout(False) End Sub #End Region Private Sub btnShowModeless_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowModeless.Click ShowTheModelessForm() End Sub Private Sub Button1btnShowOwned_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1btnShowOwned.Click ShowTheOwnedForm() End Sub Private Sub btnMessageBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMessageBox.Click ShowTheMessageBox() End Sub Private Sub btnShowModal_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnShowModal.Click ShowTheModalForm() End Sub ' show a non-modal form and get an event when it closes Sub ShowTheModelessForm() ' Declare the Form object. Dim frm As New CalleeForm() ' Create a handler for the Closing event. AddHandler frm.Closing, AddressOf CalleeForm_Closing ' Show the form. frm.Show() End Sub ' this event fires when the nonmodal form closes Private Sub CalleeForm_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) ' cast the sender argument to a specific object Dim frm As CalleeForm = DirectCast(sender, CalleeForm) ' display the value of two fields in CalleeForm lblMessage.Text = frm.Text & " is closing" & ControlChars.CrLf lblMessage.Text &= " Name = " & frm.UserName & ControlChars.CrLf & " Alias = " & frm.AliasName End Sub ' show an owned form Sub ShowTheOwnedForm() ' we use this variable to create unique captions for each form. Static counter As Integer ' Declare the Form object. Dim frm As New CalleeForm() ' create a unique caption counter += 1 frm.Text = "Callee Form #" & CStr(counter) ' Add this form to the list of owned form. Me.AddOwnedForm(frm) ' Create a handler for the Closing event. AddHandler frm.Closing, AddressOf CalleeForm_Closing ' Show the form. frm.Show() End Sub ' show a modal form Sub ShowTheModalForm() ' Declare the Form object. Dim frm As New CalleeForm() ' Show the form modally If frm.ShowDialog() = DialogResult.OK Then ' display the value of two fields in CalleeForm lblMessage.Text = "Name = " & frm.UserName & ControlChars.CrLf & "Alias = " & frm.AliasName Else ' the user canceled the dialog lblMessage.Text = "The end user canceled the action" End If End Sub ' show a MessageBox Sub ShowTheMessageBox() Dim res As DialogResult res = MessageBox.Show("File not found", "A MessageBox example", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) lblMessage.Text = "The user pressed " & res.ToString End Sub End Class